<template>
	<view class="page">
<!-- 		<view class="input-t" @tap.stop="chooseType">
			<text>申请类型</text>
			<text class="input-quick" v-model="addform.did">{{ mtype || '请选择申请类型' }} <text class="iconfont iconxia"></text></text>
		</view> -->
		
		
<!-- 		<view class="input-t">
			<text>申请类型</text>
			<picker @change="bindPickerChange" placeholder="请选择申请类型" v-model="addform.did" :value="index" :range="array" range-key="name">
				<view style="padding: 20rpx;">{{ array[index].name }}</view>
			</picker>
		</view> -->
		<view class="input-t">
		    <view class="input" style="width: 100%;display: flex;justify-content: space-between;">
				<view style="width:20%;text-align: left">会议主题</view>
				<input v-model="addform.mtTheme" type="text" style="width: 70%;text-align: right;padding-right: 30rpx;">
		    </view>
		</view>
		<view class="input-t">
		  <picker mode="selector" :range="worksType" :range-key="'mtrName'" :value="index" @change="bindPickerChange" style="width: 100%;">
		    <view class="picker" style="width: 100%;display: flex;justify-content: space-between;">
				<view style="width:20%;text-align: left">会议室</view>
				<view style="width: 70%;text-align: right;padding-right: 30rpx;">{{addform.mtrName}}</view>
		    </view>
		  </picker>
		  <view class="pi" v-if="!addform.mtrName">
		  </view>
		</view>
		<view class="input-t">
		  <picker mode="date" :value="addform.mtStime" start="2015-09-01" @change="bindDateChange" style="width: 100%;">
		    <view class="picker" style="width: 100%;display: flex;justify-content: space-between;">
				<view style="width:20%;text-align: left">开始时间</view>
				<view style="width: 70%;text-align: right;padding-right: 30rpx;">{{addform.mtStime}}</view>
		    </view>
		  </picker>
		  <view class="pi" v-if="!addform.mtStime">
		  </view>
		</view>
		
		<view class="input-t">
		  <picker mode="date" :value="addform.mtEtime" start="2015-09-01" @change="bindDateChange2" style="width: 100%;">
		    <view class="picker" style="width: 100%;display: flex;justify-content: space-between;">
				<view style="width:20%;text-align: left">结束时间</view>
				<view style="width: 70%;text-align: right;padding-right: 30rpx;">{{addform.mtEtime}}</view>
		    </view>
		  </picker>
		  <view class="pi" v-if="!addform.mtEtime">
		  </view>
		</view>
		
		
		<!-- <view class="input-t">
			<text>结束时间</text>
			<picker mode="date" :value="date" :end="endDate" @change="bindDateChange">
				<view class="input-quick">{{ date }}</view>
			</picker>
		</view> -->
		<view class="input-t">
			<text>会议描述</text>
			<text class="input-quick"></text>
		</view>
		<view class="input-body">
			<textarea placeholder="请详细描述您的会议内容..." v-model="addform.mtDescription" class="input-textare" />
		</view>
		<button
			class="confirm-btn"
			:class="'bg-' + themeColor.name"
			:disabled="btnLoading"
			:loading="btnLoading"
			@click="confirm"
		>
			提交
		</button>

	</view>
</template>

<script>

function getDate(type) {
	const date = new Date();
 
	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	let day = date.getDate();
 
	if (type === 'start') {
		year = year - 10;
	} else if (type === 'end') {
		year = year + 10;
	}
	month = month > 9 ? month : '0' + month;
	day = day > 9 ? day : '0' + day;
 
	return `${year}-${month}-${day}`;
}
export default {
	// components:{
	// 		timePicker
	// 	},
	data() {
		return {
			type:'',
			mtype:'',
			mtypeValue:'',
			remindType: [{value: '0',name: '不提醒'},{value: '1',name: '消息提醒'},{value: '2',name: '短信提醒'}],
			sendDate: {
				remind:'0',
				content: ''
			},
			// worksType:["财务流程","请假流程"],
			// worksType:[
			// 	{ name: '请假流程',id:'92ee5934-68a1-11ec-80de-9eb8d4a59510'},
			// 	{ name: '财务流程',id:'851f7f51-68a1-11ec-80de-9eb8d4a59510'}
			// ],
			worksType:[],
			array:[],
			btnLoading: false,
			// 新增
			addform:{
				mtTheme: '',
				mtDescription: '',
				mtState: '已预约',
				mtrId: '',
				mtStime: '',
				mtEtime: '',
				mtMan: '王雅婷'
			},
			// 日期
			date: getDate({
				format: true
			}),
			startDate: getDate('start'),
			endDate: getDate('end'),
			index: 2,
		};
	},
	onLoad(){
		this.getMeetroomList();
	},
	onShow() {
		uni.setNavigationBarColor({
		    frontColor: '#ffffff',
		    backgroundColor: this.themeColor.color,
		    animation: {
		        duration: 400,
		        timingFunc: 'easeIn'
		    }
		})
	},
	
	methods: {
		getMeetroomList(){
			var page = 1;
			var size = 100;
			var that = this;
			// var username=wx.getStorageSync('user');
			// username=JSON.parse(username).name
			const headers = {
				// authentication: wx.getStorageSync('tokenStr') 
				authentication:'4d58f6f9-0240-4e14-b50c-047d598493d7'
			};
			wx.request({
				url: `http://121.36.218.32:9887/clouddocument/mtr/${page}/${size}`,
				method: 'get',
				header: headers,
				// header: {
				// 	'content-type': '4094899d-d2a0-4067-9025-8aa7394bc160'
				// },
				success(resp) {
					console.log(resp.data.list)
					that.worksType = resp.data.list
					console.log('___')
					console.log(that.worksType)
				}
			})
		},
		// 类型
		bindPickerChange: function(e) {
			console.log(e);
			this.index = e.detail.value;
			this.addform.mtrId = this.worksType[e.detail.value].mtrId;
			this.addform.mtrName = this.worksType[e.detail.value].mtrName;
		},
		// 开始日期
		bindDateChange: function(e) {
			this.addform.mtStime = e.detail.value;
		},
		// 结束日期
		bindDateChange2: function(e) {
			this.addform.mtEtime = e.detail.value;
		},
		// 监听反馈类型事件
		handleRemindTypeChange(e) {
			this.sendDate.remind = e.detail.value;
		},
		chooseType() {
			uni.showActionSheet({
				itemList: this.worksType,
				success: res => {
					this.mtype = this.worksType[res.tapIndex];
					this.mtypeValue = res.tapIndex;
				},
				fail: res => {
					console.log(res);
				}
			});
		},
		// giveValue(mtype){
		// 	if(mtyp='财务流程'){
		// 		this.addform.did='92ee5934-68a1-11ec-80de-9eb8d4a59510'
		// 	}
		// 	else if(mtyp='申请流程'){
		// 		this.addform.did='851f7f51-68a1-11ec-80de-9eb8d4a59510'
		// 	}
		// },
		// // 发送数据
		// async send() {
		// 	this.$mHelper.toast('提交成功');
		// }
		confirm(){
			var obj={
					mtId: '20223',
					mtTheme: this.addform.mtTheme,
					mtDescription: this.addform.mtDescription,
					mtState: this.addform.mtState,
					// mtrId: this.addform.mtrId,
					mtrId: this.addform.mtrId,
					mtStime: this.addform.mtStime,
					mtEtime: this.addform.mtEtime,
					mtMan: '王雅婷'
				};
				
			// var fd = new FormData();
			//   fd.append('did', this.addform.did);
			//   fd.append('starter', '王雅婷');
			//   fd.append('beginDate', this.addform.beginDate);
			//   fd.append('endDate', this.addform.endDate);
			//   fd.append('quantity', 0);
			//   fd.append('description', this.addform.description);
			//   fd.append('document', 0);
			//   fd.append('privacy', 0);
			//   fd.append('hurry', 0);
			// var page = 1;
			// var size = 100;
			// var that = this;
			// var applyfind = 0;
			// var username=wx.getStorageSync('user').name;
			// const headers = {
			// 	// authentication: wx.getStorageSync('tokenStr')
			// 	authentication: '4d58f6f9-0240-4e14-b50c-047d598493d7'
			// };
			console.log(obj);
			
				
			if(this.addform.mtTheme=="" ||this.addform.mtDescription==""){
				wx.showToast({
					  title: '输入不能为空',
					  icon: 'none',
					  duration: 1500,
				})
			}
				
			else{
				wx.request({
					url: `http://121.36.218.32:9887/clouddocument/mt`,
					// url: `http://121.36.218.32:7002/mt`,
					data: obj,
					method: 'post',
					header: {
						'authentication': '4d58f6f9-0240-4e14-b50c-047d598493d7',
					},
					// formData: {
					// 	did:this.addform.did,
					// 	starter:'王雅婷',
					// 	beginDate:this.addform.beginDate,
					// 	endDate:this.addform.endDate,
					// 	quantity:0,
					// 	description:this.addform.description,
					// 	document:0,
					// 	privacy:0,
					// 	hurry:0,
					// },
					success(resp) {
						console.log(resp.data)
						that.result = resp.data
					}
				})
			}
			
			
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: $page-color-base;
}
/*表单标题*/
.input-t {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
	padding: $spacing-base;
	margin-top: $spacing-base;
	font-size: $font-base;

}
.input-quick {
	position: relative;
	padding-right: 40upx;
	.iconfont {
		font-size: $font-sm;
	}
}

.input-body {
	background: $color-white;
	padding: $spacing-sm $spacing-base;
	.gender-item {
		margin-right: 20upx;

		.gender-item-text {
			padding-left: 10upx;
		}

	}
}

.input-textare {
	height: 200upx;
	font-size: 34upx;
	line-height: 50upx;
	width: 100%;
	box-sizing: border-box;
	padding: 20upx 30upx 0;
}
.input-t{
	background-color: white;
	position: relative;
}
.pi{
	background-image: url(../../static/selectdown.png);
	position: absolute;
	right: 40rpx;
	width: 40rpx;
	height: 40rpx;
	background-size: 50% auto;
	background-size: contain;
}
</style>
